package com.duneyr.snakes.generate;

/**
 *
 * @author Daniel
 */
public class GenBlock {
    //Block types:
    public enum Type {
        EMPTY(1.4f), ROOM(10), CORRIDOR(1), STAIRS(12);
        //used for: Making corridors using Astar.
        private float cost = 1;
        private Type(float c){
        	cost = c;
        }
        public float getCost(){
        	return cost;
        }
    }
    //Directions:
    public static final byte NONE = 0;
    public static final byte EAST = 0;
    public static final byte NORTH = 1;
    public static final byte WEST = 2;
    public static final byte SOUTH = 3;
    //Wall kinds:
    public static final byte ALLWALLS = 15;
    public static final byte WALL = 1;
    public static final byte DOOR = 1<<4;
    public static final byte WALL_DOOR = WALL | DOOR;
    
    //Block Type
    public Type type;
    
    //Walls:
    public byte walls;
    
    //Extra information
    public GenRoom room;
    public GenCorridor corridor;
    
    public GenBlock(Type type) {
        this.type = type;
        walls = 0;
    }
    
    public void setType(GenRoom room){
    	type = Type.ROOM;
    	this.room = room;
    	this.corridor = null;
    }
    
    public void setType(GenCorridor corridor){
    	type = Type.CORRIDOR;
    	this.room = null;
    	this.corridor = corridor;
    }
    
    public void setTypeEmpty(){
    	type = Type.EMPTY;
    }
    
    public void setTypeStairs(){
    	type = Type.STAIRS;
    }
    
    /**
     * Set a wall (either wall or door) in a certain direction.
     * 
     * @param kind eg. WALL_DOOR
     * @param direction The direction, eg. SOUTH
     */
    public void setWall(byte kind, byte direction){
        walls = (byte) (walls | (kind << direction));
    }
    
    /**
     * Erase a wall (either wall or door) in a certain direction.
     * 
     * @param kind eg. WALL_DOOR
     * @param direction  The direction, eg. SOUTH
     */
    public void eraseWall(byte kind, byte direction){
        walls = (byte) (walls & ~(kind << direction));
    }
    
    public boolean isWallSet(byte kind, byte direction){
        return (walls & (kind << direction)) != 0;
    }
    
    /**
     * Clear everything (Walls and Doors).
     */
    public void clearAllWalls(){
        walls = 0;
    }
    
}
